package com.bigpillar.storageservice.service.impl;

import com.bigpillar.storageservice.mapper.AccountMapper;
import com.bigpillar.storageservice.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

@Service
public class AccountServiceImpl implements AccountService {
    @Resource
    private AccountMapper accountMapper;

    @Override
    public void decrease(Long userId, BigDecimal money) {
        // 模拟超时异常,全局事务回滚,feign默认超时时间为 1s
        try { TimeUnit.SECONDS.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); }
        accountMapper.decrease(userId, money);
    }
}
